package com.dollar.ruyuan_juc.promise.promiseMakeTea;

import com.dollar.ruyuan_juc.promise.noPromise.BoilWater;

import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class Promisor {
    public static Future<Object> create(long startTime) {
        /**
         * FutureTask 实现了 Runnable, Future
         */
        //step1 定义任务
        FutureTask<Object> futureTask = new FutureTask<Object>(() -> {
            System.out.println("任务一开始：烧水，需要15分钟");
            BoilWater boilWater = new BoilWater();
            try {
                Thread.sleep(15000);
                boilWater.setStatus(true);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return boilWater;
        });
        //step2 Executor 在这里执行
        new Thread(futureTask).start();
        //返回promise
        return futureTask;
    }
}
